/**
 * 配置参考:
 * https://cli.vuejs.org/zh/config/
 */
// const url = "http://192.168.1.101:9999";
const url = "http://zdkj-gateway:9999";
const path = require("path");
const webpack = require("webpack");
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const productionGzipExtensions = ["js", "css"];
module.exports = {
  lintOnSave: true,
  productionSourceMap: false,
  transpileDependencies: [
    // 可以是字符串或正则表达式
    "vue-echarts",
    "resize-detector"
  ],
  chainWebpack: config => {
    // 忽略的打包文件
    config.externals({
      axios: "axios"
    });
    const entry = config.entry("app");
    entry.add("babel-polyfill").end();
    entry.add("classlist-polyfill").end();
  },
  // 配置转发代理
  devServer: {
    disableHostCheck: true,
    port: 8080,
    proxy: {
      "/auth": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/auth": "/auth"
        }
      },
      "/admin": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/admin": "/admin"
        }
      },
      "/stm": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/stm": "/stm"
        }
      },
      "/epm": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/epm": "/epm"
        }
      },
      "/subwayst": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/subwayst": "/subwayst"
        }
      },
      "/code": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/code": "/code"
        }
      },
      "/gen": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/gen": "/gen"
        }
      },
      "/support": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/support": "/support"
        }
      },
      "/actuator": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/actuator": "/actuator"
        }
      },
      "/monitor": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/monitor": "/monitor"
        }
      },
      "/mp": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/mp": "/mp"
        }
      },
      "/daemon": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/daemon": "/daemon"
        }
      },
      "/job": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/job": "/job"
        }
      },
      "/tx": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/tx": "/tx"
        }
      },
      "/pay": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/pay": "/pay"
        }
      },
      "/act": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/act": "/act"
        }
      },
      "/check": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/check": "/check"
        }
      },
      "/rca": {
        target: url,
        ws: true,
        pathRewrite: {
          "^/rca": "/rca"
        }
      }
    }
  },
  configureWebpack: {
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"),
        "@i": path.resolve(__dirname, "./src/assets")
      }
    },
    plugins: [
      new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),

      // 下面是下载的插件的配置
      new CompressionWebpackPlugin({
        algorithm: "gzip",
        test: new RegExp("\\.(" + productionGzipExtensions.join("|") + ")$"),
        threshold: 10240,
        minRatio: 0.8
      }),
      new webpack.optimize.LimitChunkCountPlugin({
        maxChunks: 5,
        minChunkSize: 100
      })
    ]
  }
};
